package com.service.devimonitor;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.Map.Entry;

import org.apache.log4j.Logger;

import com.bpms.common.CommonUtil;
import com.bpms.common.JdbcWorker;
import com.bpms.common.VO;
import com.bpms.common.VOL;
import com.bpms.common.VOList;
import com.bpms.esb.IService;
import com.service.util.DateUtil;
import com.zk.atm.forms.AtmpDeviceStatusForm;
import com.zk.atm.service.impl.AtmpDeviceStatusServiceImpl;
import com.zk.atm.utils.AccessDBConnection;
import com.zk.atm.utils.ConstantsAtmp;
import com.zk.atm.utils.ConstantsAtmpSql;
import com.zk.atm.utils.InitDeviceStatusConfig;
import com.zk.atm.utils.JsonUtil;
import com.zk.atm.utils.PrimaryKeyUtil;
import com.zk.atm.utils.StringUtil;
import com.zk.atm.vo.AtmpDevice;
import com.zk.atm.vo.AtmpDeviceStatusCurrent;

public class Atmpdevicestatusserviceimpl implements IService {
	public static final Logger logger=Logger.getLogger(AtmpDeviceStatusServiceImpl.class);
	
	
	
	public VO exec(VO args) {
		String cmd="";
		VO return_vo=new VO();
		try{
			cmd=StringUtil.getPropertyValue(args.getAttr("cmd"));
			if(cmd.equals("")){
				cmd="execList";
			}
			if(cmd.equals(ConstantsAtmp.ATMP_DEVICE_ACTION_DETAIL_METHOD)){
				return_vo=this.show_status_detial(args);
				//System.out.println(JsonUtil.getJsonObjectByBpmVo(return_vo));
			}
			CommonUtil.debug("AtmpDeviceStatusServiceImpl "+cmd+"\r\n:success");
			return return_vo;
		}catch(Exception e){
			CommonUtil.debug("AtmpDeviceStatusServiceImpl "+cmd+"\r\n exception",e);
			return null;
		}
	}
	
	//获取状态表中,表列名对应的字典值
	Map<String,String> dict_map=new HashMap();
	Map<String,String> dict_status_map=new HashMap();
	//获取设备类型的code与名称
	Map<String,String> dict_device_type_map=new HashMap();

	protected VO show_status_detial(VO args) throws Exception{
		VO return_vo=new VO();
		try {
			JdbcWorker j=new JdbcWorker();
			String deviceip=args.getAttr("deviceip");
			String device_status_id=args.getAttr("device_status_id");
			String sql="select *from atmp_device_status_current adsc where adsc.deviceip='" +deviceip+"'"+
					" and adsc.device_status_id='"+device_status_id+"'";
//			String   sql=   " select adsc.*,adt.type_code , adt.type_name  " +
//					" from atmp_device_status_current adsc " 
//					 +" left join atmp_device_type adt  on adsc.devicetype=adt.type_code "
//					 +"   where 1=1  "
//					 +"  and adsc.deviceip='"+deviceip+"' "
//					 +"  and adsc.device_status_id='"+device_status_id+"' "
//					 +"  and adsc.devicetype is not null ";		
			VOList list=j.readAll(new VO(), sql);
			if(list.listData.size()< 1){
				String msg="当前ip:"+deviceip+",当前id:"+device_status_id+"的设备状态在数据库中不存在!";
				System.out.println("*******************************msg="+msg);
				logger.error(msg);
				return return_vo;
			}
			VO status_vo=(VO) list.listData.get(0);
			VOList new_list=new VOList();
			//获取状态表中,表列名对应的字典值,这里只加载一次,不重复加载;如果要看到新加状态后的结果,需要重启
			if(dict_map.size()==0){
			 dict_map=this.getDictIdAndValue();
			}if(dict_status_map.size()==0){
			 dict_status_map=this.getDictIdStatusAndValue();
			}
			Iterator it=status_vo.attrs().entrySet().iterator();
			while(it.hasNext()){
				VO new_vo=new VO();
				Entry<String,String> e=(Entry<String, String>) it.next();
				//列名
				String key=e.getKey().toString().toLowerCase();
				//列的对应的英文状态值
				String value=StringUtil.getPropertyValue(e.getValue());
				//列的英文状态对应的中文状态值 
				String key_cn=StringUtil.getPropertyValue(dict_map.get(key));
				//获取状态对应的中文状态值
				String column_name_value_combin_key=(key+ConstantsAtmp.ATMP_DEVICE_STATUS_PATH_SIGN_UNDER_LINE+value).toLowerCase();
				String status_cn=StringUtil.getPropertyValue(dict_status_map.get(column_name_value_combin_key));
				if(key.equals(ConstantsAtmp.ATMP_DEVICE_STATUS_CURRENT_MINUTES_TO_NOW_MARK)||
				   key.contains(ConstantsAtmp.ATMP_DEVICE_STATUS_CURRENT_STANDBY_COLUMN)||
				   key.equals(ConstantsAtmp.ATMP_DEVICE_STATUS_CURRENT_DEVICE_ID)||
				   key.equals(ConstantsAtmp.ATMP_DEVICE_STATUS_CURRENT_DEVICE_STATUS_ID)){
				   continue;
				}
				//如果是显示数值或设备主信息的列,则直接将值,显示在状态列中
				if(key.contains(ConstantsAtmp.ATMP_DEVICE_STATUS_CURRENT_COUNT)||
				   key.equals(ConstantsAtmp.ATMP_DEVICE_STATUS_CURRENT_DEVICE_NAME)||
				   key.equals(ConstantsAtmp.ATMP_DEVICE_STATUS_CURRENT_DEVICECODE)||
				   key.equals(ConstantsAtmp.ATMP_DEVICE_STATUS_CURRENT_NETWORKCODE)||
				   key.equals(ConstantsAtmp.ATMP_DEVICE_STATUS_CURRENT_DEVICEIP)||
				   key.equals(ConstantsAtmp.ATMP_DEVICE_STATUS_CURRENT_DEVICETYPE)||
				   key.equals(ConstantsAtmp.ATMP_DEVICE_STATUS_CURRENT_TIMEMARK)|| 
				   key.equals(ConstantsAtmp.ATMP_DEVICE_TYPE_NAME_KEY)|| 
				   key.equals(ConstantsAtmp.ATMP_DEVICE_TYPE_CODE_KEY)){
					status_cn=value;
				}
				new_vo.setAttr("key", key);
				new_vo.setAttr("key_cn", key_cn);
				new_vo.setAttr("value", value);
				new_vo.setAttr("status_cn", status_cn);
				new_list.listData.add(new_vo);
//				System.out.println("************key="+key+",key_cn="+key_cn+",value="+value
//						+",column_name_value_combin_key="+column_name_value_combin_key+",status_cn="+
//						status_cn);
			}
			new_list=getDeviceTypeNameByVOList(new_list);
			//System.out.println("list2="+list2);
			return_vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_RET, "0");
			return_vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_MESSAGE, "操作成功!");
			return_vo.setObj(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_VOLIST, new_list);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return return_vo;
	}
	//从device_type表中,根据status_current表中的devicetype找对应的type名称,装到list的device_name中
	protected VOList getDeviceTypeNameByVOList(VOList list) throws Exception{
		Iterator it=list.listData.iterator();
		String device_name="",devicetype="";
		//先找devicetype
		while(it.hasNext()){
			VO new_vo=(VO) it.next();
			String device_name_or_type_column=new_vo.getAttr("key");
			if(device_name_or_type_column.equals(ConstantsAtmp.ATMP_DEVICE_STATUS_CURRENT_DEVICETYPE)){
				devicetype=new_vo.getAttr("value");
			}
			if(!devicetype.equals("")){
				System.out.println("device_name="+device_name+",devicetype="+devicetype);
				break;
			}
		}
		if(dict_device_type_map.size()==0){
			dict_device_type_map=this.getDictDeviceTypeCodeAndName();
		}
		//再根据devicetype到type表中找名字,set到status_cn中
		if(!devicetype.equals("")){
			while(it.hasNext()){
				VO new_vo=(VO) it.next();
				String vo_key=new_vo.getAttr("key");
//				if(vo_key.equals(ConstantsAtmp.ATMP_DEVICE_TYPE_NAME_KEY)){
//					//设备类型,类型值
//					new_vo.setAttr("key_cn", "设备类型");
//					new_vo.setAttr("status_cn", new_vo.getAttr("value"));
//				}else if(vo_key.equals(ConstantsAtmp.ATMP_DEVICE_TYPE_CODE_KEY)){
//					//设备编码值
//					new_vo.setAttr("key_cn", "设备编码");
//					new_vo.setAttr("status_cn", new_vo.getAttr("value"));
//				}
				  // 把设备名称从,设备类型表中取出来
				if(vo_key.equals(ConstantsAtmp.ATMP_DEVICE_STATUS_CURRENT_DEVICE_NAME)){
					String device_type_name=StringUtil.getPropertyValue(dict_device_type_map.get(devicetype));
					if(!device_type_name.equals("")){
						new_vo.setAttr("status_cn", device_type_name);
						break;
					}
				}
			}
		}
		return list;
	}
	
	//获取字典的中文名称
	protected Map<String,String> getDictIdAndValue() throws Exception{
		Map<String,String> map=new HashMap();
		JdbcWorker j=null;
		try {
		    j=new JdbcWorker();
			//读取当前状态表中,所有列名的字典值
			String sql="select lower(bd.dictid) as dictid,bd.dictname from bpm_dict bd where lower(bd.dictid) in(" +
					" select lower(column_name) from all_tab_columns " +
					" where table_name='ATMP_DEVICE_STATUS_CURRENT'" +
					")";
			VOList column_dict_name_list=j.readAll(new VO(), sql);
			//System.out.println("************************show_status_detial:column_dict_name_list="+column_dict_name_list.listData);
			Iterator<VO> it=column_dict_name_list.listData.iterator();
			while(it.hasNext()){
				VO item=(VO) it.next();
				String dictid=item.getAttr("DICTID");
				String dictname=item.getAttr("DICTNAME");
				map.put(dictid, dictname);
				//System.out.println("*****************************item:dictid="+dictid+",dictname="+dictname);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			j=null;
		}
		return map;
	}
	
	//获取字典表英文状态对应的状态值
	protected Map<String,String> getDictIdStatusAndValue() throws Exception{
		Map<String,String> map=new HashMap();
		JdbcWorker j=null;
		try {
		    j=new JdbcWorker();
			//读取当前状态表中,所有列名的字典值
			String sql="select *from bpm_dictvalue bdv "
					   +"	where lower(bdv.dictid) in( "
					   +"	select lower(bd.dictid) as dictid from bpm_dict bd where lower(bd.dictid) in( "
					   +" select lower(column_name) from all_tab_columns "
					   +" where table_name='ATMP_DEVICE_STATUS_CURRENT' "
					   +") "
					   +")";
			VOList column_dict_name_list=j.readAll(new VO(), sql);
			//System.out.println("************************show_status_detial:column_dict_name_list="+column_dict_name_list.listData);
			Iterator<VO> it=column_dict_name_list.listData.iterator();
			while(it.hasNext()){
				VO item=(VO) it.next();
				String dictid=item.getAttr("DICTID");
				String k=item.getAttr("K");
				String val=item.getAttr("VAL");
				String combin_key=dictid+ConstantsAtmp.ATMP_DEVICE_STATUS_PATH_SIGN_UNDER_LINE+k;
				map.put(combin_key.toLowerCase(), val);
				//System.out.println("*****************************item:comin_key="+combin_key+",val="+val);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			j=null;
		}
		return map;
	}
	
	//获取设备类型的code与名称
	protected Map<String,String> getDictDeviceTypeCodeAndName() throws Exception{
		Map<String,String> map=new HashMap();
		JdbcWorker j=null;
		try {
		    j=new JdbcWorker();
			//读取当前状态表中,所有列名的字典值
			String sql="    select *from atmp_device_type adt ";
			VOList list=j.readAll(new VO(), sql);
			Iterator<VO> it=list.listData.iterator();
			while(it.hasNext()){
				VO item=(VO) it.next();
				//String dictid=item.getAttr("type_id");
				String key_code=item.getAttr("type_code");
				String value=item.getAttr("type_name");
				map.put(key_code, value);
				//System.out.println("*****************************item:comin_key="+combin_key+",val="+val);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally{
			j=null;
		}
		return map;
	}

	public VO execList(VO arg0) {
		JdbcWorker j=null;
		VO vo=new VO();
		try{
			j = new JdbcWorker();
			String sql =StringUtil.getPropertyValue(vo.getAttr("sql"));
			if(sql.equals("")){
				sql=" select count(*) as total,                                     "+
				"       adsc1.servicestatus,                                    "+
				"       adsc1.networkcode,                                      "+
				"       org.org_name                                            "+
				"  from atmp_device_status_current adsc1, atmp_org org          "+
				" where 1 = 1                                                   "+
				"   and adsc1.networkcode = org.org_code                        "+
				// and org.org_code in(
				//     select org.org_code from atmp_org org
				//	   where (org.parent_org_id=3 or org.org_id=3)
				//  )
				" group by org.org_name,adsc1.networkcode, adsc1.servicestatus  "+
				" order by org.org_name,adsc1.networkcode, adsc1.servicestatus  ";
			}
			VOL vol= new VOL();
			
			VOList volist=j.readAll(new VO(), sql);
			vol = new VOL(volist);
			
//			vol.columns="PAYEEACCNO,DRAWEEACCNO,EXCHANGEBANKNO,ISSUEDATE,BILLNO";
//			vol.headers="收款人账号,付款人账号,交换行号,出票日期,凭证号";
//			vol.types="TEXT,TEXT,TEXT,TEXT,TEXT";
			vo.setObj(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_VOLIST, volist);
			vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_RET, "0");
			vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_MESSAGE, "success");
//			vo.setObj("vol", vol);
		}catch (Exception e){
			CommonUtil.debug("Getbilllist exception",e);
		}
		return vo;
	}
	
    /**
     * @author zengqun
     * @remark 解析客户端http发送上来的状态，写入数据库源状态表、历史表、当前状态表中
     * 源状态表是持续插入；历史表是从源数据表中行列倒置，每上来一次状态，则插入1条；当前状态表，始终更新。
     * @date 2012-9-26
     * @version 1.0
     */
	public boolean saveDevcieStatus(AtmpDeviceStatusForm statusForm)
			throws Exception {
		boolean isSuccess=false;
		try {
			//解析http发送上来的所有状态值
			Map status_map=this.getStatusMapByStatusForm(statusForm);
			if(status_map==null||status_map.size()==0){
				String msg="saveDevcieStatus:getStatusMapByStatusForm:解析状态字符串出错,解析的map长度小于2";
				System.out.println(msg);
				logger.error(msg);
				return isSuccess;
			}
			//打印拆分后的map:状态值
			//StringUtil.printMap(status_map);
			//生成父记录的主键
			String device_ip=StringUtil.getPropertyValue(status_map.get(ConstantsAtmp.ATMP_DEVICE_STATUS_DEVICE_IP_NAME));
			String parent_device_status_id=this.getParentStatusId(device_ip);
			//把其它状态，与此主主键关联上。
			boolean success_original=this.saveDeviceStatusByParentKeyAndMap(parent_device_status_id,status_map);
			if(success_original==false){
				System.out.println("*********************saveDevcieStatus:保存到original报错！");
				logger.error("saveDevcieStatus:保存源状态出错！");
			}
			
			boolean success_history=this.saveDeviceStatusHistory(status_map);
			if(success_history==false){
				System.out.println("*********************saveDevcieStatus:保存到history报错！");
				logger.error("saveDeviceStatusHistory:保存源状态出错！");
			}
			boolean success_current=this.saveDeviceStatusCurrent(status_map);
			if(success_current==false){
				System.out.println("*********************saveDeviceStatusCurrent:保存到current报错！");
				logger.error("saveDeviceStatusCurrent:保存源状态出错！");
			}
			
			if(success_original==true&&success_history==true&&success_current==true){
				System.out.println("*************************3个都保存成功！");
				isSuccess=true;
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("出错了！");
			logger.error("saveDevcieStatus:保存源状态出错！"+e.getMessage());
		}
		return isSuccess;
	}
	
	/**
	 * @author zengqun
	 * @remark 行列倒置，把original表中的多个key，value状态值，整合成1条记录，保存到history表中。
	 * @date 2012-9-26
	 * @version 1.0
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public boolean saveDeviceStatusCurrent(Map<String,String> statusMap) throws Exception{
		boolean is_success=false;
		Connection conn=null;
		try {
			Map map=null;
			String table_name="atmp_device_status_current";
			JdbcWorker jdbcworker=new JdbcWorker();
			VO db_vo=new VO();
			String device_ip=statusMap.get(ConstantsAtmp.ATMP_DEVICE_STATUS_DEVICE_IP_NAME);
			device_ip=device_ip.trim();
			db_vo.setAttr(ConstantsAtmp.ATMP_DEVICE_STATUS_DEVICE_IP_NAME,device_ip);
			//根据惟一的ip到当前状态表中找惟一的一条记录。
			VOList list=jdbcworker.readAll(new VO(), "select device_status_id from atmp_device_status_current where deviceip='"+device_ip+"'");
			if(list!=null&&list.rowCount>0){
			  db_vo=(VO) list.listData.get(0);
			}
			String device_status_id=StringUtil.getPropertyValue(db_vo.getAttr("device_status_id"));
			VO key_vo=new VO();
			key_vo.voType=table_name;
			key_vo.keyString="device_status_id";
			VO new_vo=new VO();
			Iterator<Entry<String, String>> it=statusMap.entrySet().iterator();
			while(it.hasNext()){
				Entry<String,String> e=it.next();
				String key=e.getKey();
				String value=e.getValue();
				new_vo.setAttr(key, value);
			}
			//打上时间戳
			new_vo.setAttr("time_mark", DateUtil.getInstance().getDateFormat(new Date(), "yyyy-MM-dd HH:mm:ss"));
			System.out.println("******************************saveDeviceStatusCurrent:new_vo.getAttr('time_mark')="+new_vo.getAttr("time_mark"));
			//如果根据ip找到了记录，则是更新操作
			if(!device_status_id.equals("")){
			  key_vo.setAttr("device_status_id", device_status_id);
			  jdbcworker.update(new_vo, key_vo);
			}else{
				//map=new HashMap();
				//conn=AccessDBConnection.getConnection();
				//map.put(ConstantsAtmp.ATMP_CONNECTION_NAME,conn );
				String primary_key= PrimaryKeyUtil.getPrimaryKey(table_name, null);
				new_vo.setAttr("device_status_id",primary_key);
				new_vo.voType=table_name;
				jdbcworker.insert(new_vo);
			}
			System.out.println("保存成功!");
			is_success=true;
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("保存到：当前状态表失败!"+e.getMessage());
		}finally{
			AccessDBConnection.closeConnection(conn);
		}
		return is_success;
	}
	
	/**
	 * @author zengqun
	 * @remark 行列倒置，把original表中的多个key，value状态值，整合成1条记录，保存到history表中。
	 * @date 2012-9-26
	 * @version 1.0
	 * @param map
	 * @return
	 * @throws Exception
	 */
	public boolean saveDeviceStatusHistory(Map<String,String> statusMap) throws Exception{
		boolean is_success=false;
		Connection conn=null;
		try {
			Map map=new HashMap();
		    conn=AccessDBConnection.getConnection();
			map.put(ConstantsAtmp.ATMP_CONNECTION_NAME, conn);
			String table_name="atmp_device_status_history";
			JdbcWorker jdbcworker=new JdbcWorker();
//		List<String> table_cloumn_list=this.getDeviceStatusColumnNames(map);
			VO vo=new VO();
			Iterator<Entry<String, String>> it=statusMap.entrySet().iterator();
			while(it.hasNext()){
				Entry<String,String> e=it.next();
				String key=e.getKey();
				String value=e.getValue();
				vo.setAttr(key, value);
			}
			vo.voType=table_name;
			vo.setAttr("device_status_id", PrimaryKeyUtil.getPrimaryKey(table_name, map));
			//打上时间戳
			//vo.setObj("time_mark", new Date().toLocaleString());
			vo.setObj("time_mark", DateUtil.getInstance().getDateFormat(new Date(), "yyyy-MM-dd HH:mm:ss"));
			
			jdbcworker.insert(vo);
			System.out.println("保存成功!");
			is_success=true;
		} catch (RuntimeException e) {
			e.printStackTrace();
			logger.error("保存到：历史状态表失败!"+e.getMessage());
		}finally{
			AccessDBConnection.closeConnection(conn);
		}
		return is_success;
	}
	
	/**
	 * @author zengqun
	 * @remark 根据父id,保存所有的子状态到status_original表中
	 * @param parent_key
	 * @param statusMap
	 * @return
	 * @throws Exception
	 */
	public boolean saveDeviceStatusByParentKeyAndMap(String parent_key,Map statusMap) throws Exception {
		boolean is_success = false;
		parent_key=StringUtil.getPropertyValue(parent_key);
		if (parent_key.equals("")||statusMap == null || statusMap.size() == 0) {
			return false;
		}
		Connection conn = AccessDBConnection.getConnection();
		Map<String,Connection> connectionMap=new HashMap<String,Connection>();
		//存放conn,由主方法来获取，释放conn
		connectionMap.put(ConstantsAtmp.ATMP_CONNECTION_NAME, conn);
		String table_name = "atmp_device_status_original";
		try {
			String sql = "insert into " + table_name + "  "
					+ "(device_status_original_id,p_device_status_original_id, "
					+ "device_column_key,device_column_value ) "
					//+ "device_column_key,device_column_value,time_mark ) "
					//+ "values(?,?,?,?," + getDateValue() + ")";
			        + "values(?,?,?,?)";
			PreparedStatement pst = conn.prepareStatement(sql);
			conn.setAutoCommit(false);
			Iterator it = statusMap.entrySet().iterator();
			while (it.hasNext()) {
				Entry<String,String> e = (Entry<String,String>) it.next();
				String key = (String) e.getKey();
				String value = (String) e.getValue().toString();
				//获取主键，根据表名，找到对应的序列配置，生成处境的主键。
				pst.setString(1, PrimaryKeyUtil.getPrimaryKey(table_name, null));
				pst.setString(2, parent_key);
				pst.setString(3, key);
				pst.setString(4, value);
				pst.addBatch();
			}
			pst.executeBatch();
			conn.commit();
			pst.clearBatch();
			is_success=true;
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			AccessDBConnection.closeConnection(conn);
		}
		return is_success;
	}

	/**
	 * @remark 根據device_ip生成主鍵id值，把其它子狀態與此主id值相互关联；形成父子结构，便于状态行列倒置。
	 * @param deviceIp
	 * @return
	 * @throws Exception
	 */
	protected String getParentStatusId(String deviceIp) throws Exception {
		Connection conn = AccessDBConnection.getConnection();
		Map map=new HashMap();
		//把connection放在主方法里面，获取，释放。
		map.put(ConstantsAtmp.ATMP_CONNECTION_NAME, conn);
		String device_status_original_id="";
		try {
			Date d = new Date();
			String table_name = "atmp_device_status_original";
			String sql = "insert into " + table_name + "  "
					+ "(device_status_original_id,p_device_status_original_id, "
					+ "device_column_key,device_column_value ) "
					//+ "device_column_key,device_column_value,time_mark ) "
					//+ "values(?,?,?,?," + getDateValue() + ")";
			        + "values(?,?,?,?)";
			PreparedStatement pst = conn.prepareStatement(sql);
			String primary_key = PrimaryKeyUtil.getPrimaryKey(table_name, null);
			if (primary_key.equals("")) {
				logger.error(table_name + "：getParentStatusId:获取主键异常！");
				return "";
			}
			pst.setString(1, primary_key);
			pst.setString(2, null);
			pst.setString(3, ConstantsAtmp.ATMP_DEVICE_STATUS_DEVICE_IP_NAME);
			pst.setString(4, deviceIp);
			pst.execute();
//			sql = "select *from "+table_name+" adso where adso.device_column_key='"+ConstantsAtmp.ATMP_DEVICE_STATUS_DEVICE_IP_NAME+"'"
//					+ " and adso.device_column_value='"+ deviceIp+ "'"+ " and adso.p_device_status_original_id is null";
//			PreparedStatement pst2 = conn.prepareStatement(sql);
//			ResultSet rs = pst2.executeQuery();
//			device_status_original_id = "";
//			while (rs.next()) {
//				device_status_original_id = rs.getString("device_status_original_id");
//			}
			device_status_original_id=primary_key;
			if(logger.isDebugEnabled()){
			  System.out.println("getParentStatusId:device_status_original_id="+ device_status_original_id);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			AccessDBConnection.closeConnection(conn);
		}
		return device_status_original_id;
	}
	
	//解析http发送上来的状态字符串，存放到map中
	private Map<String,String> getStatusMapByStatusForm(AtmpDeviceStatusForm statusForm) 
	                                            throws Exception{
		Map<String,String> status_map=new HashMap<String,String>();
		String devstatus=statusForm.getDevstatus();
		//先以|拆分
		String[] strs=devstatus.split(ConstantsAtmp.ATMP_DEVICE_STATUS_SPLIT_SIGN);
		System.out.println(strs.length);
		if(strs==null||strs.length<2){
			return null;
		}
		if(!StringUtil.isEmptyStringArray(strs)){
			//取|竖线后面的字符串； 以;分号拆分
			String[] status_strs=strs[1].split(ConstantsAtmp.ATMP_DEVICE_STATUS_SPLIT_SIGN_VALUE);
			if(!StringUtil.isEmptyStringArray(status_strs)){
				for (int i = 0; i < status_strs.length; i++) {
					//对每个状态值，以:冒号拆分
					String[] each_key_value=status_strs[i].split(ConstantsAtmp.ATMP_DEVICE_STATUS_SPLIT_SIGN_KEY);
				    if(!StringUtil.isEmptyStringArray(each_key_value)){
				    	String key=each_key_value[0];
				    	String value=each_key_value[1];
				    	if(logger.isDebugEnabled()){
				    	 //System.out.println("*********************getStatusListByStatusForm:key="+key+",value="+value);
				    	}
				    	status_map.put(key, value);
				    }
				}
			}
		}
		return status_map;
	}
	
	
	
	public static String getDateValue() throws Exception {
		Date d = new Date();
		return "to_date('" + d.toLocaleString() + "','yyyy-MM-dd hh24:mi:ss')";
	}
	
	/**
	 * @author zengqun
	 * @remark 更新当前状态表,把所有处于正常服务状态的数据,扫描一遍日志,凭单,通用打印机,纸盒1,2,3,4
	 *         查看是否有少纸的;如果有,则把正常服务状态:置为报警状态.
	 * @date 2012-9-28
	 * @version 1.0
	 * @param argsMap
	 * @return
	 * @throws Exception
	 */
	public boolean taskScannerDeviceStatusCurrentWarning(Map argsMap)
	  throws Exception{
		boolean is_scanner_ok=false;
		JdbcWorker jw=null;
		try {
			String sql="update atmp_device_status_current adsc                     "+
			"   set adsc.servicestatus = '"+ConstantsAtmp.ATMP_DEVICE_STATUS_EARLY_WARNING+"'                      "+
			" where adsc.device_status_id in                            "+
			"       (select adsc1.device_status_id                      "+
			"          from atmp_device_status_current adsc1            "+
			"         where 1 = 1                                       "+
			"           and adsc1.servicestatus = '"+ConstantsAtmp.ATMP_DEVICE_STATUS_INSERVICE+"'           "+
			"           and (adsc1.receiptprinter = '"+ConstantsAtmp.ATMP_DEVICE_STATUS_LOWOFPAPER+"' or     "+
			"               adsc1.journalprinter = '"+ConstantsAtmp.ATMP_DEVICE_STATUS_LOWOFPAPER+"' or      "+
			"               adsc1.generalprinter = '"+ConstantsAtmp.ATMP_DEVICE_STATUS_LOWOFPAPER+"' or      "+
			"               adsc1.generalprintertray1 = '"+ConstantsAtmp.ATMP_DEVICE_STATUS_LOWOFPAPER+"' or "+
			"               adsc1.generalprintertray2 = '"+ConstantsAtmp.ATMP_DEVICE_STATUS_LOWOFPAPER+"' or "+
			"               adsc1.generalprintertray3 = '"+ConstantsAtmp.ATMP_DEVICE_STATUS_LOWOFPAPER+"' or "+
			"               adsc1.generalprintertray4 = '"+ConstantsAtmp.ATMP_DEVICE_STATUS_LOWOFPAPER+"' or " +
					     "  adsc1.stamper='"+ConstantsAtmp.ATMP_DEVICE_STATUS_LOWINK+"')" +
				     ")  ";
		    jw=new JdbcWorker();
			jw.execute(sql);
			is_scanner_ok=true;
			//if(logger.isDebugEnabled()){
			  System.out.println("定时任务1:************************扫描并更新预警状态成功!");
			//}
			//System.out.println("更新预警成功!is_scanner_ok="+is_scanner_ok);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("扫描并更新预警状态失败!"+e.getMessage());
		}finally{
			 jw=null;
		}
		return is_scanner_ok;
	}
	
	/**
	 * @author zengqun
	 * @remark 更新当前状态表,把所有记录的数据的最新一次上报时间即time_mark与当前时间即sysdate相比
	 *         把其相差的分钟数,写到minutes_from_time_mark_to_now的列中.
	 * @date 2012-9-28
	 * @version 1.0
	 * @param argsMap
	 * @return
	 * @throws Exception
	 */
	public boolean taskDeviceStatusCurrentDifferMinutesEndNow(Map argsMap) 
	   throws Exception{
		boolean is_success=false;
		Connection conn=null;
		try {
		    conn=(Connection) argsMap.get(ConstantsAtmp.ATMP_CONNECTION_NAME);
			if(conn==null||conn.isClosed()){
				conn=AccessDBConnection.getConnection();
			}
			String device_sql=StringUtil.getPropertyValue(argsMap.get(ConstantsAtmpSql.ATMP_CURRENT_STATUS_TASK_DEVICE_IP_LIST_SQL_NAME));
			String differ_minutes_sql=StringUtil.getPropertyValue(argsMap.get(ConstantsAtmpSql.ATMP_CURRENT_STATUS_TASK_DIFFER_MINUTES_SQL_NAME));
			if(device_sql.equals("")){
				device_sql=ConstantsAtmpSql.ATMP_CURRENT_STATUS_TASK_DEVICE_IP_LIST_SQL;
			}
			//获取所有的deviceip
			List<String> deviceIpList=new ArrayList<String>();
			PreparedStatement pst=conn.prepareStatement(device_sql);
			ResultSet rs=pst.executeQuery();
			while(rs.next()){
				String device_ip=rs.getString("deviceip");
				deviceIpList.add(device_ip);
			}
			if(logger.isDebugEnabled()){
			  System.out.println("定时任务2:获取deviceip数据成功!共计"+deviceIpList.size()+"条");
			}
			//开始批处理,所有的设备的截止到当前的时间差.从最近的一次时间标记,到系统时间的相差时间,以分钟计算.
			conn.setAutoCommit(false);
			if(differ_minutes_sql.equals("")){
				differ_minutes_sql= ConstantsAtmpSql.ATMP_CURRENT_STATUS_TASK_DIFFER_MINUTES_SQL;
			}
			pst=conn.prepareStatement(differ_minutes_sql);
			for (String obj : deviceIpList) {
				String device_ip=StringUtil.getPropertyValue(obj);
				if(device_ip.equals("")){
					continue;
				}
				pst.setString(1, obj);
				pst.setString(2, obj);
				pst.addBatch();
			}
			int[]  differ_numbers= pst.executeBatch();
			conn.commit();
			pst.clearBatch();
			is_success=true;
			if(logger.isDebugEnabled()){
			  System.out.println("定时任务2:批量更新--截止当前时间,累计停报时间差成功!更新的记录数为"+differ_numbers.length+"条");
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("taskDeviceStatusCurrentDifferMinutesEndNow:批量更新报停时间差失败!"+e.getMessage());
		} finally{
			AccessDBConnection.closeConnection(conn);
		}
		return is_success;
	}
	
	/**
	 * 设备状态监控的map,初始化参数值
	 */
	Map device_status_config_map=new TreeMap();
	/**
	 * @author zengqun
	 * @remark 更新当前状态表,判断minutes_from_time_mark_to_now中的分钟数是否大于60分钟;
	 * 如果大于,则更新状态为报停状态.
	 * @date 2012-9-29
	 * @version 1.0
	 * @param argsMap
	 * @return
	 * @throws Exception
	 */
	public boolean taskDeviceStatusCurrentQuit(Map argsMap) 
	   throws Exception{
		boolean is_success=false;
		Connection conn=null;
		if(argsMap==null){
			argsMap=new HashMap();
		}
		//获取报停的时间阀值
		String device_status_report_quit_seconds=ConstantsAtmpSql.ATMP_CURRENT_STATUS_TASK_UPDATE_REPORT_QUIT_MINUTES_VALUE;;
		if(device_status_config_map==null||device_status_config_map.size()==0){
			device_status_config_map=InitDeviceStatusConfig.getDeviceStatusConfigMap(null);
		}
		String seconds_value=StringUtil.getPropertyValue(device_status_config_map.get(ConstantsAtmpSql.ATMP_CURRENT_STATUS_TASK_UPDATE_REPORT_QUIT_MINUTES_NAME));
	    //System.out.println("********************taskDeviceStatusCurrentQuit:seconds_value="+seconds_value);
		if(!seconds_value.equals("")){
	    	device_status_report_quit_seconds=seconds_value;
	    }
		try {
		    conn=(Connection) argsMap.get(ConstantsAtmp.ATMP_CONNECTION_NAME);
		    if(conn==null||conn.isClosed()){
		    	conn=AccessDBConnection.getConnection();
		    }
			String sql=StringUtil.getPropertyValue(argsMap.get(ConstantsAtmpSql.ATMP_CURRENT_STATUS_TASK_UPDATE_REPORT_QUIT_SQL_NAME));
			//开始批处理,所有的设备的截止到当前的时间差.从最近的一次时间标记,到系统时间的相差时间,以分钟计算.
			conn.setAutoCommit(false);
			if(sql.equals("")){
			  sql=   ConstantsAtmpSql.ATMP_CURRENT_STATUS_TASK_UPDATE_REPORT_QUIT_SQL;
			}
			PreparedStatement pst=conn.prepareStatement(sql);
			pst.setString(1, ConstantsAtmp.ATMP_DEVICE_STATUS_REPORT_QUIT);
			//pst.setString(2, ConstantsAtmpSql.ATMP_CURRENT_STATUS_TASK_UPDATE_REPORT_QUIT_MINUTES_VALUE);
			pst.setString(2, device_status_report_quit_seconds);
			//System.out.println("taskDeviceStatusCurrentQuit:sql="+sql);
			//使用批处理,一定要加上addBatch这句,否则sql是不执行滴
			pst.addBatch();
			int[]  differ_numbers= pst.executeBatch();
			conn.commit();
			pst.clearBatch();
			is_success=true;
			if(logger.isDebugEnabled()){
			  System.out.println("定时任务3:*************************批量更新(是否)报停状态成功!");
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("taskDeviceStatusCurrentQuit:批量更新(是否)报停状态失败!"+e.getMessage());
		}finally{
			AccessDBConnection.closeConnection(conn);
		}
		return is_success;
	}
	
	Map connectionMap=new HashMap();
	public boolean taskDeviceStatusDifferMinutesAndQuit()
	  throws Exception{
		boolean is_success=false;
		Connection conn=null;
		try {
			if(connectionMap==null||connectionMap.equals("")){
				connectionMap=new HashMap();
			}
			conn=AccessDBConnection.getConnection();
			connectionMap.put(ConstantsAtmp.ATMP_CONNECTION_NAME, conn);
			//更新时间差值,用于判断设备是否报停
			taskDeviceStatusCurrentDifferMinutesEndNow(connectionMap);
			//更新设备状态,根据差值是否大于60分钟,更新状态为报停
			taskDeviceStatusCurrentQuit(connectionMap);
			//更新设备预警,只对InService状态的进行更新.报停的,维护的都不用其更新为预警.
			taskScannerDeviceStatusCurrentWarning(connectionMap);
			if(logger.isDebugEnabled()){
			  System.out.println("定时任务执行结果:定时任务:扫描预警,更新报停时间差,更新(超出"+ConstantsAtmpSql.ATMP_CURRENT_STATUS_TASK_UPDATE_REPORT_QUIT_MINUTES_VALUE+"分钟的时间范围)的设备为:报停状态的定时任务成功!");
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.out.println("定时任务执行结果:定时任务:扫描预警,更新报停时间差,更新(超出"+ConstantsAtmpSql.ATMP_CURRENT_STATUS_TASK_UPDATE_REPORT_QUIT_MINUTES_VALUE+"分钟的时间范围)的设备为:报停状态的定时任务成功!");
		}finally{
			AccessDBConnection.closeConnection(conn);
			connectionMap.clear();
		}
		return is_success;
	}

	public static void main(String[] args) {
		try{
//		VO vo = new VO();
//		vo.setAttr("cmd", "queryList");
//		
//		VO result = new Atmpdevicestatusserviceimpl().exec(vo);
//		String json=JsonUtil.getJsonObjectByBpmVo(result);
//		System.out.println("json="+json);
//		CommonUtil.debug(result);
//		Map map=new HashMap();
			//更新预警状态的定时任务
		Atmpdevicestatusserviceimpl service=new Atmpdevicestatusserviceimpl();
		//service.testSaveDeviceStatus();
		service.taskDeviceStatusCurrentQuit(null);
		//service.taskDeviceStatusCurrentQuit(map);
	    //service.taskDeviceStatusDifferMinutesAndQuit();
	    //service.taskScannerDeviceStatusCurrentWarning(null);
		//service.queryDeviceStatusList(null);
		//测试查看明细
		VO vo=new VO();
		vo.setAttr("cmd", ConstantsAtmp.ATMP_DEVICE_ACTION_DETAIL_METHOD);
		vo.setAttr("device_status_id", "9");
		vo.setAttr("deviceip", "192.168.1.100");
		//service.exec(vo);
		} catch (Exception e) {
			System.out.println("patch fault!");
			e.printStackTrace();
		}
	}  
	
	public void testSaveDeviceStatus(){
		//System.out.println(new Date().toLocaleString());
		try {
//			JdbcWorker jdbcWorker=new JdbcWorker();
//			jdbcWorker.execute("insert into atmp_device_status_original (device_status_original_id,p_device_status_original_id,device_column_key,device_column_value,time_mark )values(4,'','DeviceIp','192.168.0.188',to_date('2012-9-24','yyyy-MM-dd'))" +
//					           "insert into atmp_device_status_original (device_status_original_id,p_device_status_original_id,device_column_key,device_column_value,time_mark )values(5,'','DeviceIp','192.168.0.188',to_date('2012-9-24','yyyy-MM-dd'));" +
//					"");
//			System.out.println("patch success!");
			Atmpdevicestatusserviceimpl deviceService=new Atmpdevicestatusserviceimpl();
			AtmpDeviceStatusForm form=new AtmpDeviceStatusForm();
			//OutService  DeviceError
			String devstatus="001234|DeviceIP:192.168.1.100;stamper:Nomarl;" +
				     "ServiceStatus:OutService;"+
					"GeneralPrinter:NoSupport;IDCardReader:Normal;ICCardreader:Nomarl;" +
					"PersonCardReader:Normal;NetWorkCode:SZ001-003;DeviceCode:SZ_GS_00010"
					;
			//devstatus="0023";
			form.setDevstatus(devstatus);
			deviceService.saveDevcieStatus(form);
			//Map statusMap=deviceService.getStatusMapByStatusForm(form);
			//deviceService.saveDeviceStatusHistory(statusMap);
			//deviceService.saveDeviceStatusCurrent(statusMap);
//			String[] dev1=devstatus.split("\\|");
//			for (String string : dev1) {
//				System.out.println(string);
//			}
			
			//Map map=new HashMap();
			//map.put("sql", "select *from atmp_device_status_current where rownum=1");
			//deviceService.getDeviceStatusColumnNames(map);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public List<AtmpDeviceStatusCurrent> getDeviceStatusList(AtmpDeviceStatusForm form) 
	   throws Exception{
		List<AtmpDeviceStatusCurrent> list=new ArrayList();
		Connection conn=AccessDBConnection.getConnection();
		try {
			if(conn==null||conn.isClosed()){
				logger.error("获取conn失败!");
				return null;
			}
			String device_name=form.getCurrentVo().getDevice_name();
			String deviceip=form.getCurrentVo().getDeviceip();
			String servicestatus=form.getCurrentVo().getServicestatus();
			String networkcode=form.getCurrentVo().getNetworkcode();
			String userid=form.getUserid();
			//分页的sql
//			  select *from (
//					     select rownum as rn, adsc.* from atmp_device_status_current adsc where 1=1 
//					     ) adsc1
//					     where adsc1.rn>=6
//					     and rownum<10;
			String device_sql="select distinct adsc.*,ad.belong_org_name,ad.belong_org_code," +
					" bd.val as servicestatus_cn,adt.type_name as devicetype_name " +
					" from atmp_device_status_current adsc " +
					" left join bpm_dictvalue bd on adsc.servicestatus = bd.k " +
					" left join atmp_device_type adt" +
					" on adsc.devicetype=adt.type_code" +
					"  left join atmp_device ad" +
					"  on adsc.networkcode=ad.belong_org_code " +
					" where 1=1 " ;
			if(!userid.equals("")){
					String belong_codes=ConstantsAtmpSql.getBelongOrgCodes(form);
					if(!belong_codes.equals("")){
					   device_sql+=" and adsc.networkcode in ("+belong_codes+")";
					}
					//device_sql+=ConstantsAtmpSql.ATMP_PERM_SQL.replaceAll("#userid#", userid);
//				device_sql+=" and adsc.networkcode in ";
//				device_sql+=ConstantsAtmpSql.ATMP_PERM_ORG_CODE_SQL.replaceAll("#userid#", userid);
			}
			if(!device_name.equals("")){
				device_sql+=" and (adsc.device_name like '%"+device_name+"%' or adt.type_name like '%"+device_name+"%')";
			}
			if(!deviceip.equals("")){
				device_sql+=" and adsc.deviceip like '%"+deviceip+"%'";
			}
			if(!servicestatus.equals("")){
				//device_sql+=" and adsc.servicestatus like '%"+servicestatus+"%'";
				device_sql+=" and bd.val like '%"+servicestatus+"%'";
			}
			if(!networkcode.equals("")){
				device_sql+=" and adsc.networkcode like '%"+networkcode+"%'";
			}
			device_sql+=" order by adsc.networkcode,adsc.servicestatus,adsc.deviceip ";
			System.out.println("**********************************getDeviceStatusList:sql="+device_sql);
			AtmpStatusCurrentReflect reflect=new AtmpStatusCurrentReflect();
			list=reflect.getListByClassName(device_sql, "com.zk.atm.vo.AtmpDeviceStatusCurrent");
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			AccessDBConnection.closeConnection(conn);
		}
		return list;
	}
	
	/**
	 * @author zengqun
	 * @remark 获取所有设备的列表
	 * @date 2012-10-9
	 * @version 1.0
	 * @param form
	 * @return
	 * @throws Exception
	 */
	public List<AtmpDevice> getDeviceList(AtmpDeviceStatusForm form) 
	   throws Exception{
		List<AtmpDevice> list=new ArrayList();
		Connection conn=AccessDBConnection.getConnection();
		try {
			if(conn==null||conn.isClosed()){
				logger.error("获取conn失败!");
				return null;
			}
			String device_name=StringUtil.getPropertyValue(form.getDevice_vo().getDevice_name());
			String deviceip=StringUtil.getPropertyValue(form.getDevice_vo().getDevice_ip());
			String userid=StringUtil.getPropertyValue(form.getUserid());
			//String networkcode=form.getCurrentVo().getNetworkcode();
			String belong_org_name=StringUtil.getPropertyValue(form.getDevice_vo().getBelong_org_name());
			//分页的sql
//			  select *from (
//					     select rownum as rn, adsc.* from atmp_device_status_current adsc where 1=1 
//					     ) adsc1
//					     where adsc1.rn>=6
//					     and rownum<10;
			//String device_sql="select * from atmp_device adsc where 1=1 ";
			String device_sql=" select adsc.*, adt.type_code, adt.type_name "
							 +" from atmp_device adsc "
							 +"  left join atmp_device_type adt "
							 +"   on adsc.device_type_id = adt.type_id "
							 +" where 1 = 1 ";
			//加上数据权限的功能 2012-11-19
			if(!userid.equals("")){
				String belong_ids=ConstantsAtmpSql.getBelongOrgIds(form);
				if(!belong_ids.equals("")){
				   device_sql+=" and adsc.belong_org_id in ("+belong_ids+")";
				}
				//device_sql+=ConstantsAtmpSql.ATMP_PERM_SQL.replaceAll("#userid#", userid);
			}
			if(!device_name.equals("")){
				device_sql+=" and adsc.device_name like '%"+device_name+"%'";
			}
			if(!deviceip.equals("")){
				device_sql+=" and adsc.device_ip like '%"+deviceip+"%'";
			}
			if(!belong_org_name.equals("")){
				device_sql+=" and adsc.belong_org_name like '%"+belong_org_name+"%'";
			}
//			if(!networkcode.equals("")){
//				device_sql+=" and adsc.belong_org_code like '%"+networkcode+"%'";
//			}
			System.out.println("**********************************getDeviceList:sql="+device_sql);
			AtmpStatusCurrentReflect reflect=new AtmpStatusCurrentReflect();
			list=reflect.getListByClassName(device_sql, "com.zk.atm.vo.AtmpDevice");
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			AccessDBConnection.closeConnection(conn);
		}
		return list;
	}
	
	public String queryDeviceStatusList(AtmpDeviceStatusForm statusForm) throws Exception {
			JdbcWorker j=null;
			VO vo=new VO();
			VOList volist=null;
			try{
				j = new JdbcWorker();
				String sql="select device_status_id,device_id,device_name,devicetype,deviceip,networkcode,devicecode," +
						" servicestatus,time_mark from atmp_device_status_current where 1=1 ";
				String device_name="";
				String device_ip="";
				String device_type="";
				volist=j.readAll(new VO(), sql);
				VOL vol=new VOL(volist);
//				vol.columns="DEVICENO,DEVICENAME,NETNUM,ATMIPADDRESS,VIRTUALCNUM";
//				vol.headers="设备编号,设备名称,网点号,IP地址,虚拟柜员号";
//				vol.types="TEXT,TEXT,TEXT,TEXT,TEXT,TEXT,TEXT";
				
				vo.setObj("vol", vol);	
				vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_RET, "0");
				vo.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_MESSAGE, "success");
				vo.setObj(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_VOLIST, volist);
				
//				vo.setAttr("primaryKey", "DEVICENO");
//				vo.setAttr("result", "0000");
			}catch (Exception e){
				CommonUtil.debug("Getatmdevice exception",e);
				vo.setAttr("result", "9999");
				vo.setAttr("msg", "获得ATM设备错误");
			}
			String json_strs=JsonUtil.getJsonObjectByBpmVo(vo);
			System.out.println("json_str="+json_strs.toLowerCase());
			return json_strs.toLowerCase();
	}
	
	
	
}
